<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据名称列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>绑定的社区名称：</label>
                                <input type="text" name="mapStrName"/>
                            </li>
                            <li>
                                <label>数据名称：</label>
                                <input type="text" name="mapTitle"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('haode_show')}" required>
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="addMap()" shiro:hasPermission="system:map:add">
                    <i class="fa fa-plus"></i> 同步卫星用户表数据(列表已存在的不会再次修改或删除)
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:map:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:map:remove')}]];
        var prefix = ctx + "system/map";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "地图数据",
                columns: [
                {
                    field: 'dataMapId', 
                    title: '地图数据',
                    visible: false
                },
                {
                    field: 'mapTitle', 
                    title: '数据名称'
                },
                {
                    field: 'mapLnglat', 
                    title: '经纬度'
                },
                {
                    field : 'status',
                    title : '状态',
                    formatter: function(value, item, index) {
                    if (item.status == '1') {
                        return '<span class="label label-default">显示</span>';
                    }
                    else if (item.status == '0') {
                        return '<span class="label label-danger">隐藏</span>';
                    }

                    }
                },
                {
                    field: 'mapContent', 
                    title: '数据介绍'
                },
                {
                    field: 'mapAddress', 
                    title: '具体地址'
                },
                {
                    field: 'mapStrName', 
                    title: '绑定的社区名称'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.dataMapId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.dataMapId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function addMap(){
            $.ajax({
                method: "POST",
                url: ctx + "haode/v1/map/add",
                contentType: 'application/json',
                dataType: 'json',
                cache: false,
                async: false,//异步,避免请求卡顿现象
                data: JSON.stringify({
                    type: 1
                }),
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $.table.refresh();
                    } else {
                         $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("获取数据失败。");
                }
            });
        }

    </script>
</body>
</html>